﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TargetLockGridBehaviour : MonoBehaviour
{
    public GameObject lockGameObject;
    private GameObject targetGrid;

    void Start()
    {
        targetGrid = GameObject.FindGameObjectWithTag(StaticDataManager.TARGET_GRID_TAG);
    }

    void Update()
    {
        CheckTargetObject();
    }

    public void LockTarget(GameObject gameObject)
    {
        lockGameObject = gameObject;

        ShowTargetGrid();
    }

    public void UnlockTarget()
    {
        if (lockGameObject)
        {
            lockGameObject = null;
        }
    }

    public void ShowTargetGrid()
    {
        if (targetGrid.transform.localScale == Vector3.one)
        {
            return;
        }
        targetGrid.transform.localScale = Vector3.one;
    }

    public void HideTargetGrid()
    {
        if (targetGrid.transform.localScale == Vector3.zero)
        {
            return;
        }

        targetGrid.transform.localScale = Vector3.zero;
    }

    public void CheckTargetObject()
    {
        if (!lockGameObject)
        {
            return;
        }

        targetGrid.transform.position = lockGameObject.transform.position;
    }
}
